﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.SectionProperties
{
    [XmlRoot("pgMar", Namespace = Constants.WordMain)]
    public class PageMargins : XmlSerializable, ISectionPropElement
    {
        [XmlAttribute("top", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Top { get; set; }

        [XmlAttribute("right", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Right { get; set; }

        [XmlAttribute("bottom", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Bottom { get; set; }

        [XmlAttribute("left", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Left { get; set; }

        [XmlAttribute("header", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Header { get; set; }

        [XmlAttribute("footer", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Footer { get; set; }

        [XmlAttribute("gutter", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Gutter { get; set; }

        public PageMargins() { }

        public void Copy(object obj)
        {
            if (obj is PageSize)
            {
                this.Top = (obj as PageMargins).Top;
                this.Right = (obj as PageMargins).Right;
                this.Bottom = (obj as PageMargins).Bottom;
                this.Left = (obj as PageMargins).Left;
                this.Header = (obj as PageMargins).Header;
                this.Footer = (obj as PageMargins).Footer;
                this.Gutter = (obj as PageMargins).Gutter;
            }
        }
    }
}
